import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface GeneralStack<T> {
	public T push(T item);

	public T pop();

	public T peek();

	public boolean empty();

	public int size();
}

class ArrayListGeneralStack<T> implements GeneralStack<T> {
	List<T> list = new ArrayList<T>();

	@Override
	public T push(T item) {
		if (item == null)
			return null;
		list.add(item);
		return item;
	}

	@Override
	public T pop() {
		if (list.isEmpty())
			return null;
		return (T) list.remove(list.size() - 1);
	}

	@Override
	public T peek() {
		if (list.isEmpty())
			return null;
		return (T) list.get(list.size() - 1);
	}

	@Override
	public boolean empty() {
		if (list.isEmpty())
			return true;
		return false;
	}

	@Override
	public int size() {
		return list.size();
	}

	@Override
	public String toString() {
		return list + "";
	}

}

class Car1 {
	private int id;
	private String name;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Car1 [id=" + id + ", name=" + name + "]";
	}

}

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			String str = in.next();
			if (str.equals("quit"))
				return;
			else if (str.equals("Integer")) {
				System.out.println("Integer Test");
				int m = in.nextInt();
				int n = in.nextInt();
				GeneralStack<Integer> stack = new ArrayListGeneralStack<Integer>();
				for (int i = 0; i < m; i++) {
					System.out.println("push:" + stack.push(in.nextInt()));
				}
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + stack.pop());
				}
				System.out.println(stack.toString());
				System.out.println(stack.getClass().getInterfaces()[0]);
			} else if (str.equals("Double")) {
				System.out.println("Double Test");
				int m = in.nextInt();
				int n = in.nextInt();
				GeneralStack<Double> stack = new ArrayListGeneralStack<Double>();
				for (int i = 0; i < m; i++) {
					System.out.println("push:" + stack.push(in.nextDouble()));
				}
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + stack.pop());
				}
				System.out.println(stack.toString());
				System.out.println(stack.getClass().getInterfaces()[0]);
			} else if (str.equals("Car")) {
				System.out.println("Car Test");
				int m = in.nextInt();
				int n = in.nextInt();
				GeneralStack<Car1> stack = new ArrayListGeneralStack<Car1>();
				for (int i = 0; i < m; i++) {
					Car1 car = new Car1();
					car.setId(in.nextInt());
					car.setName(in.next());
					System.out.println("push:" + stack.push(car));
				}
				for (int i = 0; i < n; i++) {
					System.out.println("pop:" + stack.pop().toString());
				}
				System.out.println(stack.toString());
				System.out.println(stack.getClass().getInterfaces()[0]);
			}
		}
		in.close();
	}
}
